package com.sugon.controller.module;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.ModuleDataEntity;
import com.sugon.service.ModuleDataService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 模具资料信息Controller
 *
 * @author sugon
 * @date 2019-07-31 10:20:50
 */
@Controller
@RequestMapping("moduledata")
public class ModuleDataController {
    @Autowired
    private ModuleDataService moduleDataService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("moduledata:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ModuleDataEntity> moduleDataList = moduleDataService.queryList(query);
        int total = moduleDataService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(moduleDataList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("moduledata:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        ModuleDataEntity moduleData = moduleDataService.queryObject(id);

        return R.ok().put("moduleData", moduleData);
    }

    /**
     * 保存
     */
    @AutoLog("模具管理-模具资料管理新增")
    @RequestMapping("/save")
    @RequiresPermissions("moduledata:save")
    @ResponseBody
    public R save(@RequestBody ModuleDataEntity moduleData) {
        moduleDataService.save(moduleData);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("模具管理-模具资料管理修改")
    @RequestMapping("/update")
    @RequiresPermissions("moduledata:update")
    @ResponseBody
    public R update(@RequestBody ModuleDataEntity moduleData) {
        moduleDataService.update(moduleData);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("模具管理-模具资料管理删除")
    @RequestMapping("/delete")
    @RequiresPermissions("moduledata:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        moduleDataService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ModuleDataEntity> list = moduleDataService.queryList(params);

        return R.ok().put("list", list);
    }

    /**
     * 审核
     */
    @RequestMapping("/review")
    @RequiresPermissions("moduledata:review")
    @ResponseBody
    public R review(@RequestBody ModuleDataEntity moduleData) {
        moduleDataService.review(moduleData);

        return R.ok();
    }

    /**
     * 复审
     */
    @RequestMapping("/recheck")
    @RequiresPermissions("moduledata:recheck")
    @ResponseBody
    public R recheck(@RequestParam("id") String id, @RequestParam("knowledge") String knowledge, @RequestParam("reviewStatus") String reviewStatus) {
        moduleDataService.recheck(id, knowledge, reviewStatus);
        return R.ok();
    }
}
